package com.iSnail.ms.gather.db;

import java.io.FileInputStream;
import java.sql.Connection;
import java.util.Properties;

import org.apache.commons.dbcp.BasicDataSource;
import org.apache.commons.dbcp.BasicDataSourceFactory;

import com.iSnail.ms.util.Const;

public class ConnPool {
	private static BasicDataSource dataSource = null;

	private ConnPool() {
	}

	public static void init() throws Exception {
		if (dataSource != null) {
			dataSource.close();
			dataSource = null;
		}

		Properties properties = new Properties();

		properties.load(new FileInputStream(Const.CONFIG_FILE));

		dataSource = (BasicDataSource) BasicDataSourceFactory.createDataSource(properties);

	}

	public static synchronized Connection getConenction() throws Exception {
		if (dataSource == null) {
			init();
		}
		return dataSource.getConnection();
	}
}